package com.ebc.eservice.controller.pc;

import com.ebc.eservice.service.EbcIntroductService;
import com.ebc.eservice.util.JsonResult;
import com.ebc.eservice.util.common.constant.ApiTextHelperConstant;
import com.ebc.eservice.util.common.constant.DeveloperConstant;
import com.ebc.eservice.vo.Intro.IntroductionReqVo;
import com.ebc.eservice.vo.Intro.IntroductionUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author: Joey
 * @Description:
 * @date:2022/9/18 0:25
 */
@Api(tags = "后台管理系统-[个性化简介]")
@RestController
@RequestMapping("/IntroMange")
public class IntroManageController {

    @Autowired
    private EbcIntroductService introductService;


    @ApiOperation(value = "获取个性简介列表", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getIntroList")
    public JsonResult getCompanyList(){
        int current=1;
        int size = 50;
        return introductService.getIntroductionList(current,size);
    }
    @ApiOperation(value = "增加个性化简介", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/addIntro")
    public JsonResult addIntroduction(@RequestBody IntroductionReqVo introductionReqVo){
        return introductService.addIntroduction(introductionReqVo);
    }
    @ApiOperation(value = "添加个性化简介照片", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/addIntroPic")
    public JsonResult addIntroductionPic(Integer IntroId, MultipartFile articleFile) throws IOException {
        return introductService.addIntroPic(IntroId,articleFile);
    }
    @ApiOperation(value = "模块开关-[暂时停用]", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH
            +" 参数: 简介id、分类名字、开关 1开0关")
    @PostMapping("/updateIntroOpen")
    public JsonResult updateIntroOpen(IntroductionUpdateVo introductionUpdateVo){
        return introductService.updateOpen(introductionUpdateVo);
    }
    @ApiOperation(value = "修改个性化简介", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/updateIntro")
    public JsonResult updateIntroduction(@RequestParam(value = "picFile") MultipartFile picFile,
                                         @RequestParam(value = "introId") Integer introId,
                                         @RequestParam(value = "typeName") String typeName,
                                         @RequestParam(value = "content") String content) throws IOException {
        IntroductionUpdateVo updateVo = new IntroductionUpdateVo();
        //id typeName content file
        updateVo.setPicFile(picFile).setId(introId).setTypeName(typeName).setContent(content);

        return introductService.updateIntroduction(updateVo);
    }

    @ApiOperation(value = "删除个性化简介", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/deleteIntro")
    public JsonResult deleteIntroById(Integer IntroId){
        System.out.println("=============删除个性化简介 :"+IntroId);
        return introductService.deleteIntroduction(IntroId);
    }


}
